package com.wu.stations;

import com.jfinal.core.Controller;

/**
 * Created by WU_JF on 2015/12/30.
 */
public class StationsController extends Controller {
    public void index(){
//        renderText("this's a controller");
        System.out.println("invok StationsController index modth");
        Object stationList = Stations.me.paginate(getParaToInt(0,1),15);
        setAttr("stationsList",stationList);
        setAttr("testname","aaaa");
        //renderJsp("list.html");
        render("list.html");
        //render("/view/station/testJsp.jsp");
    }

    public  void delete(){
        //System.out.println(getPara(0));
        Stations.me.deleteById(getPara(0));
        redirect("/view/station");
    }

    public void edit(){
        System.out.println(Stations.me.findById(getPara(0)));
        setAttr("station",Stations.me.findById(getPara(0)));
        render("edit.html");
    }

    public void update(){
//        System.out.println(getModel(Stations.class));
//        System.out.println(Stations.me.findById(getPara(0)));

        Stations st =  Stations.me.findById(getPara(0));

        String names = getPara("station.names");
        String description = getPara("station.description");

        st.set("names",names);
        st.set("description",description);
        st.update();
        redirect("/view/station");
    }
}
